class Solution(object):
    def minimumDeletions(self, nums):
        n = len(nums)
        min_val = min(nums)
        min_index = nums.index(min_val)
        max_val = max(nums)
        max_index = nums.index(max_val)
        index1, index2 = min(min_index, max_index), max(min_index, max_index)
        left_max = max(index1, n - 1 - index2, index2 - index1 - 1)
        return n - left_max